import random
import sys



"""
该程序用于批量生成指定类型的随机数据库数据
"""

print("{:=^60}".format("生成数据库数据"))

type_data = []
type_data_range = {}
for i in range(100):
    item = input(f"请输入第{i+1}列的数据类型\n如下选择:'int','char','float'\n")
    if item not in ["int", "char", "float"]:
        print("类型错误,程序结束!")
        sys.exit()
    type_data.append(item)

    if item == "int":
        print("请输入整数的范围:")
        range_int_front = int(input("起始数字:\n"))
        range_int_back = int(input("结束数字:\n"))
        type_data_range["range_int_front"] = range_int_front
        type_data_range["range_int_back"] = range_int_back
    elif item == "char":
        print("请输入字符串序列用于产生随机字符串数据:")
        char_list = []
        for i in range(100):
            item = input(f"请输入第{i+1}个字符串:\n例如:'张三','李四','王五'\n")
            char_list.append(item)
            choice = input("继续添加字符串序列请按'1'\n结束请按'2'\n")
            if choice == "2":
                break
        type_data_range["range_char"] = char_list
    elif item == "float":
        print("请输入浮点数的范围:")
        range_float_front = float(input("起始数字:\n"))
        range_float_back = float(input("结束数字:\n"))
        type_data_range["range_float_front"] = range_float_front
        type_data_range["range_float_back"] = range_float_back

    choice = input("继续添加下一列数据类型请按'1'\n结束请按'2'\n")
    if choice == "2":
        break

total = int(input("请输入要生成数据的总个数:\n"))
total_data = []

for i in range(total + 1):
    all_type = {}
    for one in type_data:
        if one == "int":
            random_int = random.randint(
                type_data_range["range_int_front"],
                type_data_range["range_int_back"],
            )
            all_type["int"] = random_int
        elif one == "char":
            random_fruit = random.choice(type_data_range["range_char"])
            all_type["char"] = random_fruit
        elif one == "float":
            random_float = random.uniform(
                type_data_range["range_float_front"],
                type_data_range["range_float_back"],
            )
            all_type["float"] = random_float
    total_data.append(all_type)

print("{:=^60}".format("数据生成完毕"))

table_name = input("请输入表名:\n")

for line in total_data:
    table_data = []
    for item,data in line.items():
        table_data.append(data)
    table_data_tuple = tuple(table_data)
    print(f"INSERT INTO {table_name} VALUES {table_data_tuple};")

print("{:=^60}".format("程序运行结束"))